package 策略模式;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

//维护算法
public class Context {
    private Strategy strategy;

    public Context(Strategy strategy){
        this.strategy = strategy;
    }
    public void ContextInterface(){
        strategy.AlgorithmInterface();
    }

    public static void main(String[] args) {

        int [] nums2 = {2,0,2,3,1};
        moveZeroes(nums2);
        System.out.println(nums2);
    }
    public static void moveZeroes(int[] nums) {
        ArrayList list = new ArrayList();
        for(int i = 0;i < nums.length;i++){
            if(nums[i] == 0){
                list.add(i);
            }else{
                if(!list.isEmpty()){
                    switchNumber(nums,(int)list.get(0),i--);
                    list.remove(0);
                }
            }
        }
        System.out.println(list);
    }
    public static void switchNumber(int [] nums,int m,int n){
        int temp = nums[m];
        nums[m] = nums[n];
        nums[n] = temp;
    }

}
